Skip to content

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Jan 25, 2026

Description

LCORE-1226: ability to export configuration schema

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Tools used to create PR

  • Assisted-by: N/A
  • Generated by: N/A

Related Tickets & Documents

  • Related Issue #LCORE-1226

Summary by CodeRabbit

  • New Features
    • Added a -s / --dump-schema command-line option to export the configuration schema in OpenAPI 3.0.0 format (JSON), enabling generation of schema documentation and API specifications alongside the existing configuration dump capability.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 25, 2026

Walkthrough

A new command-line option -s/--dump-schema was added to dump the application's configuration schema as an OpenAPI 3.0.0 JSON file. A new utility module generates the schema and the entry point now invokes it and exits when the flag is used.

Changes

Cohort / File(s) Summary
Documentation
README.md
Added documentation for new -s, --dump-schema command-line option
Entry Point
src/lightspeed_stack.py
Added -s / --dump-schema CLI argument; imports utils.schema_dumper; main() calls schema_dumper.dump_schema("schema.json"), logs outcome, and exits when flag is provided
Schema Generation Utility
src/utils/schema_dumper.py
New module adding dump_schema(filename: str) to produce an OpenAPI 3.0.0 document from the Configuration model and recursive_update(original: dict) to adjust schema constructs (e.g., anyOf with null, exclusiveMinimum → minimum)

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant CLI as lightspeed_stack (CLI)
  participant Dumper as schema_dumper
  participant FS as Filesystem

  User->>CLI: invoke with `-s/--dump-schema`
  CLI->>Dumper: call dump_schema("schema.json")
  Dumper->>Dumper: generate pydantic JSON schema\napply recursive_update
  Dumper->>FS: write OpenAPI JSON to "schema.json"
  FS-->>Dumper: write result
  Dumper-->>CLI: return success/failure
  CLI-->>User: log result and exit
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly describes the main change: adding the ability to export configuration schema, which is the core feature implemented across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/utils/schema_dumper.py`:
- Around line 38-62: The dump_schema function may write None for
components.schemas if schemas.get("$defs") is missing and its docstring is too
terse; update dump_schema to use schemas.get("$defs", {}) so an empty dict is
written instead of None, expand the docstring to Google style including Args
(filename: str) and Raises (IOError/OSError for file operations and any
exceptions from models_json_schema), and extract the hardcoded "0.3.0" into a
named constant (e.g., SCHEMA_VERSION) placed in an appropriate constants module
and referenced from dump_schema; locate these changes around the dump_schema
function and usages of models_json_schema, Configuration, and recursive_update
to implement the fixes.
🧹 Nitpick comments (3)
src/lightspeed_stack.py (3)

18-18: Import style inconsistency with coding guidelines.

The coding guidelines specify using absolute imports for internal modules (e.g., from authentication import get_auth_dependency). Consider using the absolute import form.

Proposed fix
-from utils import schema_dumper
+from utils.schema_dumper import dump_schema

Then update line 122:

-            schema_dumper.dump_schema("schema.json")
+            dump_schema("schema.json")

28-42: Docstring missing documentation for the new -s/--dump-schema option.

The function docstring lists the CLI options but doesn't include the newly added -s/--dump-schema flag.

Proposed docstring update
 def create_argument_parser() -> ArgumentParser:
     """Create and configure argument parser object.

     The parser includes these options:
     - -v / --verbose: enable verbose output
     - -d / --dump-configuration: dump the loaded configuration to JSON and exit
+    - -s / --dump-schema: dump configuration schema into OpenAPI-compatible file and exit
     - -c / --config: path to the configuration file (default "lightspeed-stack.yaml")
     - -g / --generate-llama-stack-configuration: generate a Llama Stack
                                                  configuration from the service configuration
     - -i / --input-config-file: Llama Stack input configuration filename (default "run.yaml")
     - -o / --output-config-file: Llama Stack output configuration filename (default "run_.yaml")

     Returns:
         Configured ArgumentParser for parsing the service CLI options.
     """

79-96: Docstring for main() should document the new --dump-schema behavior.

The docstring describes behavior for --dump-configuration and --generate-llama-stack-configuration but doesn't mention --dump-schema.

Proposed docstring update
     Parses command-line arguments, loads the configured settings, and then:
     - If --dump-configuration is provided, writes the active configuration to
       configuration.json and exits (exits with status 1 on failure).
+    - If --dump-schema is provided, writes the configuration schema to
+      schema.json in OpenAPI-compatible format and exits (exits with status 1 on failure).
     - If --generate-llama-stack-configuration is provided, generates and stores
       the Llama Stack configuration to the specified output file and exits
       (exits with status 1 on failure).

Comment on lines 38 to 62
def dump_schema(filename: str) -> None:
"""Dump the configuration schema into OpenAPI-compatible JSON file."""
with open(filename, "w", encoding="utf-8") as fout:
# retrieve the schema
_, schemas = models_json_schema(
[(model, "validation") for model in [Configuration]],
ref_template="#/components/schemas/{model}",
)

# fix the schema
schemas = recursive_update(schemas)

# add all required metadata
openapi_schema = {
"openapi": "3.0.0",
"info": {
"title": "Lightspeed Core Stack",
"version": "0.3.0",
},
"components": {
"schemas": schemas.get("$defs"),
},
"paths": {},
}
json.dump(openapi_schema, fout, indent=4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# First, explore the project structure
echo "=== Project Structure ==="
git ls-files | head -20

# Check if constants.py exists
echo -e "\n=== Checking for constants.py ==="
find . -name "constants.py" -type f

# Check for any VERSION-related constants
echo -e "\n=== Searching for VERSION constants ==="
rg -n "^VERSION\s*=" --type py

# Look at the actual schema_dumper.py file
echo -e "\n=== Checking schema_dumper.py ==="
cat -n src/utils/schema_dumper.py

# Check for version strings in the codebase
echo -e "\n=== Searching for '0.3.0' ==="
rg "0\.3\.0" --type py

# Check imports in schema_dumper.py
echo -e "\n=== Checking models_json_schema ==="
rg -n "models_json_schema" --type py -B 2 -A 2

Repository: lightspeed-core/lightspeed-stack

Length of output: 4358


🏁 Script executed:

#!/bin/bash

# Check what's in constants.py
echo "=== Contents of constants.py ==="
cat -n src/constants.py

# Check imports in schema_dumper.py to understand what's available
echo -e "\n=== Current imports in schema_dumper.py ==="
head -n 10 src/utils/schema_dumper.py

# Look at pyproject.toml or setup.py to see version definition
echo -e "\n=== Checking for version in pyproject.toml ==="
rg -n "version\s*=" . -t toml | head -10

# Check if there are any version-related patterns in the codebase
echo -e "\n=== Searching for __version__ ==="
rg -n "__version__" --type py

Repository: lightspeed-core/lightspeed-stack

Length of output: 7933


🏁 Script executed:

#!/bin/bash

# Check version.py
echo "=== Contents of version.py ==="
cat -n src/version.py

# Check if there's any schema version constant defined elsewhere
echo -e "\n=== Searching for schema version references ==="
rg -n "schema.*version\|protocol.*version" --type py -i

# Check how the codebase typically uses versions
echo -e "\n=== Checking version usage patterns ==="
rg -n "from version import\|from constants import" --type py | head -20

# Look at pydantic documentation or test to see what models_json_schema returns
echo -e "\n=== Checking if there are tests for dump_schema ==="
find . -name "*test*schema*dumper*" -o -name "*test*dump_schema*" 2>/dev/null

# Check if schemas.get("$defs") is used elsewhere
echo -e "\n=== Searching for schemas.get or \\\$defs references ==="
rg -n '\$defs|schemas\.get' --type py

Repository: lightspeed-core/lightspeed-stack

Length of output: 813


Address the potential None value from schemas.get("$defs") and expand the docstring per Google conventions.

  1. schemas.get("$defs") could return None if the key doesn't exist, which would set "schemas": None in the output. Use schemas.get("$defs", {}) to provide a default empty dictionary.
  2. Expand the docstring to include Args and Raises sections per Google Python conventions, as required by the coding guidelines.
  3. The hardcoded "0.3.0" appears to be an intentional schema/OpenAPI version (separate from the app version in version.py). If this should be a constant, define SCHEMA_VERSION or similar in constants.py rather than importing a non-existent VERSION constant.
Proposed improvements
 def dump_schema(filename: str) -> None:
-    """Dump the configuration schema into OpenAPI-compatible JSON file."""
+    """Dump the configuration schema into OpenAPI-compatible JSON file.
+
+    Args:
+        filename: Path to the output JSON file.
+
+    Raises:
+        IOError: If the file cannot be written.
+    """
     with open(filename, "w", encoding="utf-8") as fout:
         # retrieve the schema
         _, schemas = models_json_schema(
             [(model, "validation") for model in [Configuration]],
             ref_template="#/components/schemas/{model}",
         )

         # fix the schema
         schemas = recursive_update(schemas)

         # add all required metadata
         openapi_schema = {
             "openapi": "3.0.0",
             "info": {
                 "title": "Lightspeed Core Stack",
                 "version": "0.3.0",
             },
             "components": {
-                "schemas": schemas.get("$defs"),
+                "schemas": schemas.get("$defs", {}),
             },
             "paths": {},
         }
         json.dump(openapi_schema, fout, indent=4)
🤖 Prompt for AI Agents
In `@src/utils/schema_dumper.py` around lines 38 - 62, The dump_schema function
may write None for components.schemas if schemas.get("$defs") is missing and its
docstring is too terse; update dump_schema to use schemas.get("$defs", {}) so an
empty dict is written instead of None, expand the docstring to Google style
including Args (filename: str) and Raises (IOError/OSError for file operations
and any exceptions from models_json_schema), and extract the hardcoded "0.3.0"
into a named constant (e.g., SCHEMA_VERSION) placed in an appropriate constants
module and referenced from dump_schema; locate these changes around the
dump_schema function and usages of models_json_schema, Configuration, and
recursive_update to implement the fixes.

@tisnik tisnik merged commit f18791c into lightspeed-core:main Jan 25, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant